/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package orm.impl;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;
import orm.*;

public class Tbv_medidaDAOImpl implements orm.dao.Tbv_medidaDAO {
	public Tbv_medida loadTbv_medidaByORMID(int me_id_medida) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_medidaByORMID(session, me_id_medida);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_medida getTbv_medidaByORMID(int me_id_medida) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return getTbv_medidaByORMID(session, me_id_medida);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_medida loadTbv_medidaByORMID(int me_id_medida, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_medidaByORMID(session, me_id_medida, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_medida getTbv_medidaByORMID(int me_id_medida, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return getTbv_medidaByORMID(session, me_id_medida, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_medida loadTbv_medidaByORMID(PersistentSession session, int me_id_medida) throws PersistentException {
		try {
			return (Tbv_medida) session.load(orm.Tbv_medida.class, new Integer(me_id_medida));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_medida getTbv_medidaByORMID(PersistentSession session, int me_id_medida) throws PersistentException {
		try {
			return (Tbv_medida) session.get(orm.Tbv_medida.class, new Integer(me_id_medida));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_medida loadTbv_medidaByORMID(PersistentSession session, int me_id_medida, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Tbv_medida) session.load(orm.Tbv_medida.class, new Integer(me_id_medida), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_medida getTbv_medidaByORMID(PersistentSession session, int me_id_medida, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Tbv_medida) session.get(orm.Tbv_medida.class, new Integer(me_id_medida), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_medida[] listTbv_medidaByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return listTbv_medidaByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_medida[] listTbv_medidaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return listTbv_medidaByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_medida[] listTbv_medidaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_medida as Tbv_medida");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Tbv_medida[]) list.toArray(new Tbv_medida[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_medida[] listTbv_medidaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_medida as Tbv_medida");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Tbv_medida[]) list.toArray(new Tbv_medida[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_medida loadTbv_medidaByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_medidaByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_medida loadTbv_medidaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_medidaByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_medida loadTbv_medidaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Tbv_medida[] tbv_medidas = listTbv_medidaByQuery(session, condition, orderBy);
		if (tbv_medidas != null && tbv_medidas.length > 0)
			return tbv_medidas[0];
		else
			return null;
	}
	
	public Tbv_medida loadTbv_medidaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Tbv_medida[] tbv_medidas = listTbv_medidaByQuery(session, condition, orderBy, lockMode);
		if (tbv_medidas != null && tbv_medidas.length > 0)
			return tbv_medidas[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateTbv_medidaByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return iterateTbv_medidaByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTbv_medidaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return iterateTbv_medidaByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTbv_medidaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_medida as Tbv_medida");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTbv_medidaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_medida as Tbv_medida");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_medida createTbv_medida() {
		return new orm.Tbv_medida();
	}
	
	public boolean save(orm.Tbv_medida tbv_medida) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().saveObject(tbv_medida);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(orm.Tbv_medida tbv_medida) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().deleteObject(tbv_medida);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Tbv_medida tbv_medida)throws PersistentException {
		try {
			orm.Tbv_producto[] lTbv_productos = tbv_medida.tbv_producto.toArray();
			for(int i = 0; i < lTbv_productos.length; i++) {
				lTbv_productos[i].setTbv_medidame_id_medida(null);
			}
			return delete(tbv_medida);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Tbv_medida tbv_medida, org.orm.PersistentSession session)throws PersistentException {
		try {
			orm.Tbv_producto[] lTbv_productos = tbv_medida.tbv_producto.toArray();
			for(int i = 0; i < lTbv_productos.length; i++) {
				lTbv_productos[i].setTbv_medidame_id_medida(null);
			}
			try {
				session.delete(tbv_medida);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(orm.Tbv_medida tbv_medida) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().getSession().refresh(tbv_medida);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(orm.Tbv_medida tbv_medida) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().getSession().evict(tbv_medida);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_medida loadTbv_medidaByCriteria(Tbv_medidaCriteria tbv_medidaCriteria) {
		Tbv_medida[] tbv_medidas = listTbv_medidaByCriteria(tbv_medidaCriteria);
		if(tbv_medidas == null || tbv_medidas.length == 0) {
			return null;
		}
		return tbv_medidas[0];
	}
	
	public Tbv_medida[] listTbv_medidaByCriteria(Tbv_medidaCriteria tbv_medidaCriteria) {
		return tbv_medidaCriteria.listTbv_medida();
	}
}
